﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.Rules;

namespace Authorization
{
    public class CanRead : AuthorizationBase
    {
        public CanRead(Csla.Core.IPropertyInfo PrimaryProperty, int Priority, string AuthorizationMessage)
            : base(PrimaryProperty, Priority, AuthorizationMessage)
        {
            InputProperties = new List<Csla.Core.IPropertyInfo> { PrimaryProperty };
        }

        protected override void Execute(Csla.Rules.RuleContext context)
        {
            var target = (Csla.Core.BusinessBase)context.Target;
            if (!target.CanReadProperty(PrimaryProperty))
                context.AddInformationResult(AuthorizationMessage);
        }

    }
}
